﻿package scripts{
	import flash.accessibility.Accessibility;
	import flash.accessibility.AccessibilityProperties;
	import flash.system.Capabilities;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import flash.text.AntiAliasType
	import flash.display.MovieClip;
	import flash.events.Event;
	import fl.motion.MotionEvent;
	import flash.events.MouseEvent;

	public class ClickableText extends BaseClass{
		public  var _ID:int;
		private var _myTextFmt:TextFormat;
		private var _myEventName:String;
		private var _graphicBtn:MovieClip=null;
		private var _mytext:TextField;
		private var auto_width:Number;
		public function ClickableText(headingContent:String,clickable:Boolean,strName,textfieldW:Number=0) {
			// constructor code
			super(TextField);
			if(_component && _component is TextField)
			{
				_myTextFmt = new TextFormat();
				_myTextFmt.font = Arial.REGULAR.fontName;
				_myTextFmt.color = 0xFFFFFF;
				_myTextFmt.size = 17.6;
				_myTextFmt.align = "left";
				_myTextFmt.leading = 0;
				_myTextFmt.letterSpacing =0;// -0.1;
				_mytext=TextField(_component);
				_mytext.multiline=true;
				_mytext.antiAliasType=AntiAliasType.ADVANCED;
				_mytext.embedFonts = true;
				_mytext.mouseWheelEnabled=false;
				_mytext.selectable=false;
				_mytext.wordWrap=true;
				auto_width=textfieldW;
				if(auto_width)
					_mytext.width=textfieldW;
				_mytext.htmlText=headingContent;
				update();
				if(clickable){
					_myEventName="GO_YEAR";
					_graphicBtn=new graphicBG();
					_graphicBtn.name=strName;
					_graphicBtn.width=this._component.width;
					_graphicBtn.height=this._component.height;
					//graphicBtn.y=-10;
					_graphicBtn.alpha=0;
					addChild(_graphicBtn);
					setEnable();
				}
				else
					 setDisable();
				tabEnabled = true;
				accDesc=headingContent;
			}
		}
		public function setHtmlText(textVal):void{
			_mytext.htmlText=textVal;
			update();
			accDesc=textVal;
		}
		public function setLetterSpacing(size:Number):void{
			_myTextFmt.letterSpacing=size;
			update();
		}
		override public function clickHandler(e:Event):void{
			var e:Event = new Event(_myEventName);
			dispatchEvent(e);
		
		}
		public function setHeight(num_height:Number):void{
			if(_graphicBtn!=null){
				_graphicBtn.height=num_height;
				_mytext.y=(_graphicBtn.height-_mytext.height)*0.5;
				//trace(_graphicBtn.y+","+_mytext.y);
			}
		}
		public function set EventName(str:String):void{
			_myEventName=str;
		}
		public function set text_Align(str:String):void{
			_myTextFmt.align=str;
			update();
		}
		
		public function set setBold(bool:Boolean):void{
			_myTextFmt.bold=bool;
			update();
		}
		public function setFontSize(size:Number):void{
			
			_myTextFmt.size =size;
			
			update();
			if(_graphicBtn!=null){	
			   	_graphicBtn.width=this._component.width;
				_graphicBtn.height=this._component.height;
			}
			
		}
		public function setColour(colour):void{
			_myTextFmt.color =colour;
			update();
		}
		public function update(){
			_mytext.setTextFormat(_myTextFmt);
			if(this.auto_width!=0)
				_mytext.autoSize=TextFieldAutoSize.LEFT;
		}

	}
}
